// geometry.h
//
// Hexworld consists of hexagonal tiles, edges that run between pairs
// of tiles, and nodes where three hexagonal tiles meet at a point.  A
// hexagonal grid is substantially more awkward to work with than with
// a square grid.  This goal of this module is to make this job
// easier in two specific ways:
//
// * It establishes a special coordinate system such that every node,
//   edge, and hexagonal tile is represented by a distinct (x, y)
//   coordinate pair.  Thus, a given pair of integers (x, y) refers to
//   exactly one of the following: a node, an edge, a tile, or nothing.
//
// * It sheds light on adjacency relationships.  Given the (x, y)
//   coordinates of an object (which could be a node, edge, or tile),
//   one can get all of the adjacent objects of a given type.  For
//   example, given the coordinates of a hexagonal tile are (x0, y0),
//   then one can determine the coordinates of the six adjacent edges.
//
// Details about the coordinate system are described in the .cc file,
// since these are irrelevant to a user.

#ifndef _GEOMETRY_H_
#define _GEOMETRY_H_

namespace Geometry {

  // Init() must be called before other functions.
  void Init();

  // These functions reflect the type of geometric entity associated
  // with an (x, y) pair.  At most one function returns true.
  bool IsTile(int x, int y);
  bool IsEdge(int x, int y);
  bool IsNode(int x, int y);

  // These functions return the number of tiles, edge, and nodes
  // adjacent to the the geometric entity at (x, y).  Note that:
  // - Each tile is adjacent to 6 tiles, 6 edges, and 6 nodes.
  // - Each edge is adjacent to 2 tiles, 4 edges, and 2 nodes.
  // - Each node is adjacent to 3 tiles, 3 edges, and 3 nodes.
  int NumAdjTiles(int x, int y);
  int NumAdjEdges(int x, int y);
  int NumAdjNodes(int x, int y);

  // These functions return the coordinates of objects adjacent to the
  // object with coordinates (x, y).  The parameter i should be in the
  // range 0 to NumAdjTiles(x, y) - 1 for AdjTile() and likewise for
  // the other two functions.
  void AdjTile(int x, int y, int i, int *tx, int *ty);
  void AdjEdge(int x, int y, int i, int *ex, int *ey);
  void AdjNode(int x, int y, int i, int *nx, int *ny);

  // Return the coordinates of a canonical "origin" tile.
  void GetOriginTile(int *tx, int *ty);
};

#endif // _GEOMETRY_H_
